/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qlvbdq.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import qlvbdq.dconnection.SQLServerConnect;
import qlvbdq.dto.CTBaoCaoNoDTO;

/**
 *
 * @author tuan
 */
public class CTBaoCaoNoDAO {
   
    public ArrayList<CTBaoCaoNoDTO> getCTBaoCaoNoByMaBaoCaoNo(String MaBaoCaoNo) throws SQLException {
        ArrayList<CTBaoCaoNoDTO> listCTPDV = new ArrayList<>();
        Object[] objs = { MaBaoCaoNo };
        CTBaoCaoNoDTO ctBaoCaoNo = new CTBaoCaoNoDTO();
        ResultSet rs = SQLServerConnect.getInstance().getDataFromStore("GetAllCTBCNOOfBCNFromDataBase( ? )", objs);
        while (rs.next()) {
            ctBaoCaoNo.setMaBaoCao(rs.getString("MABAOCAO"));
            ctBaoCaoNo.setMaKhachHang(rs.getString("MAKHACHHANG"));
            ctBaoCaoNo.setNoDauKy(rs.getInt("NODAUKY"));
            ctBaoCaoNo.setPhatSinh(rs.getInt("PHATSINH"));
            ctBaoCaoNo.setNoCuoiKy(rs.getInt("NOCUOIKY"));
            listCTPDV.add(ctBaoCaoNo);
        }
        return listCTPDV;
    }
    
//    public ArrayList<CTBaoCaoNoDTO> getCTBaoCaoNoByMaBaoCaoAndMaSP(String MaBaoCaoNo, String MaSP) throws SQLException {
//        ArrayList<CTBaoCaoNoDTO> listCTPDV = new ArrayList<>();
//        Object[] objs = { MaBaoCaoNo, MaSP };
//        CTBaoCaoNoDTO ctBaoCaoNo = new CTBaoCaoNoDTO();
//        ResultSet rs = SQLServerConnect.getInstance().getDataFromStore("GetCTBaoCaoNoByMaDVFromDatabase( ?, ? )", objs);
//        while (rs.next()) {
//            ctBaoCaoNo.setMaBaoCaoNo(rs.getString("MABAOCAOTON"));
//            ctBaoCaoNo.setMaSP(rs.getString("MASP"));
//            ctBaoCaoNo.setSoLuongBan(rs.getInt("SOLUONGBAN"));
//            ctBaoCaoNo.setSoLuongMua(rs.getInt("SOLUONGMUA"));
//            ctBaoCaoNo.setTonDauKy(rs.getInt("TONDAUKY"));
//            ctBaoCaoNo.setTonCuoiky(rs.getInt("TONCUOIKY"));
//            listCTPDV.add(ctBaoCaoNo);
//        }
//        return listCTPDV;
//    }
    
    public int insertCTBaoCaoNo(CTBaoCaoNoDTO ctBaoCaoNo) {
        Object[] objs = { ctBaoCaoNo.getMaBaoCao(), ctBaoCaoNo.getMaKhachHang(), ctBaoCaoNo.getNoDauKy(), 
                            ctBaoCaoNo.getPhatSinh(), ctBaoCaoNo.getNoCuoiKy()};
        return SQLServerConnect.getInstance().updateDataToDatabase("InsertCTBCNOToDataBase(?, ?, ?, ?, ?)", objs);
    }
    
   //xoa toan bo chi tiet cua BaoCaoNo do
    public int deleteCTBaoCaoNoByMaBaoCao(CTBaoCaoNoDTO ctBaoCaoNo) {
        Object[] objs = { ctBaoCaoNo.getMaBaoCao()};
        return SQLServerConnect.getInstance().updateDataToDatabase("DeleteAllCTBCNOOfBCNFromDataBase(?)", objs);
    }
    
    //delete 1 CT
    public int deleteCTBaoCaoNoByMaPhieuMaDV(CTBaoCaoNoDTO ctBaoCaoNo) {
        Object[] objs = { ctBaoCaoNo.getMaBaoCao(), ctBaoCaoNo.getMaKhachHang()};
        return SQLServerConnect.getInstance().updateDataToDatabase("DeleteCTBCNOFromDataBase(?, ?)", objs);
    }    
}
